import {
  SetMetadata,
  createParamDecorator,
  ExecutionContext,
  applyDecorators,
} from '@nestjs/common';
import type { Request } from 'express';

export const CustomDecorator = (args: string[]) => {
  console.log('自定义修饰器', args); // 在定义装饰器时执行一次
  return SetMetadata('role', args);
};

// 自定义参数装饰器返回一个url
export const paramDecoratorTest = createParamDecorator(
  (data: string, ctx: ExecutionContext) => {
    const req = ctx.switchToHttp().getRequest<Request>();
    console.log('定义自定义参数修饰器', req.url);
    return req.url;
  },
);
